package com.mingqijia.gassafety.shared.constant;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author zhangfei
 * @version 1.0.0
 * @ClassName DeviceStatusEnum.java
 * @Description TODO
 * @createTime 2023年11月07日
 */
@Getter
@RequiredArgsConstructor
public enum DeviceStatusEnum {
    DEVICE_TYPE_0("离线",0),
    DEVICE_TYPE_1("正常",1),
    DEVICE_TYPE_2("低报",2),
    DEVICE_TYPE_3("高报",3),
    DEVICE_TYPE_4("故障",4),
    DEVICE_TYPE_5("过期",5);

    private final String name;
    private final Integer code;

    public static DeviceStatusEnum parse(Integer code) {
        List<DeviceStatusEnum> filtered = Arrays.stream(values())
                .filter(item -> Objects.equals(item.getCode(), code))
                .collect(Collectors.toList());
        return CollectionUtils.isEmpty( filtered ) ? DEVICE_TYPE_0 : filtered.get(0);
    }
}